package com.heart.house.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 配置拦截器先后执行顺
 *
 * @author Luo Zhen
 * @create 2019-06-20 15:51
 */
@Configuration
public class WebMvcConf extends WebMvcConfigurerAdapter {


    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private AuthActionInterceptor authActionInterceptor;

    /**
     * 注入两个拦截器  设置先后顺序
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).excludePathPatterns("/static").addPathPatterns("/**");
        registry.addInterceptor(authActionInterceptor)
                .addPathPatterns("/accounts/profile")
                .addPathPatterns("/house/toAdd")
                .addPathPatterns("/house/add")
                .addPathPatterns("/house/ownlist")
                .addPathPatterns("/house/bookmarked")
                .addPathPatterns("/comment/leaveComment")
                .addPathPatterns("/comment/leaveBlogComment");
        super.addInterceptors(registry);
    }
}
